package com.wry.controller;

import com.wry.api.ApiService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1> dubbo服务降级 <h1>
 *
 * @author wry
 * @since 2023/5/11 13:57
 */
@RestController
public class FallbackController {

    @DubboReference(
            registry = {"nacos","zookeeper"},// 可以选择多注册中心 Dubbo会先进行注册中心的负载均衡（轮询，随机等） ，选择哪个注册中心
            version = "2.0", // 指定调用v1.0的版本服务
            protocol = "dubbo", // 指定dubbo协议
            loadbalance = "consistenthash" // loadbalance:负载均衡算法 consistenthash：一致性hash算法
            ,mock = "com.wry.controller.MockApiService", // 服务降级
            cluster = "failfast" // 集群容错 快速失败
            ,timeout = 1500
    )
    private ApiService apiService;

    @GetMapping("fallback")
    public String fallback(){
        return apiService.test("FallbackController");
    }
}
